﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SchoolCardSystem
{
    public partial class FogetPass : System.Web.UI.Page
    {
        //定义数据库信息
        MySqlConnection connection = new MySqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["connection"].ConnectionString.ToString());
                
        String name;
        String cardid;
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //取消按钮
        protected void reset_Click(object sender, EventArgs e)
        {
            Response.Redirect("Login.aspx");
        }

        protected void confirm_Click(object sender, EventArgs e)
        {
            if (idText.Text.Trim() == "") {
                errorText.Text = "请输入卡号";
                errorText.Style["display"] = "inline";
            }
            else if (nameText.Text.Trim() == "")
            {
                errorText.Text = "请输入姓名";
                errorText.Style["display"] = "inline";
            }
            else {
                //获取用户输入的信息
                cardid = idText.Text.Trim();
                name = nameText.Text.Trim();
                //打开数据库
                connection.Open();
                string sqlstr = @"select userName from user where userId=@userId";
                //Command 查询语句
                MySqlCommand cmd = new MySqlCommand(sqlstr, connection);
                //设置@userId的类型
                cmd.Parameters.Add(new MySqlParameter("@userId", MySqlDbType.VarChar, 11));
                cmd.Parameters["@userId"].Value = cardid;
                //在线模式
                MySqlDataReader dr = cmd.ExecuteReader();
                //查询失败
                if (!dr.Read() || name !=dr["userName"].ToString())
                {
                    errorText.Text = "信息不符";
                    errorText.Style["display"] = "inline";
                }
                //查询成功
                else
                {
                    //则跳转到密码修改页面
                    Session["findName"] = name;
                    Response.Redirect("ResetPass.aspx");
                }
                connection.Close();
            }
        }
    }
}